﻿@using Jugg.Admin.Framework.Menu
@using Jugg.Mapping.Category

@helper RenderMenuItem(CategoryMapping item, List<CategoryMapping> list)
{
string href = string.Empty;
if (!String.IsNullOrEmpty(item.RouteName))
{
    href = Url.RouteUrl(item.RouteName);
}
if (!String.IsNullOrEmpty(item.Controller) && !String.IsNullOrEmpty(item.Action))
{
    href = Url.Action(item.Action, item.Controller);
}
    <li id="@item.ResouceID" class="@(Request.Url.LocalPath.Equals(href,StringComparison.InvariantCultureIgnoreCase)?"active":"")">
        @{
            var childNodes = list.Where(o => o.FatherResource == item.SysResource && o.IsMenu).OrderBy(o => o.Sort).ThenBy(o => o.Name).ToList();
        }
        <a href="@(!String.IsNullOrEmpty(href)?href:"javascript:")" class="@(childNodes.Any()?"dropdown-toggle":"")">
            <i class="@item.CssClass"></i>
            <span class="menu-text"> @item.Name </span>
            @if (childNodes.Any())
            {
                <span class="badge badge-primary">@childNodes.Count()</span>
                <b class="arrow fa fa-angle-down"></b>
            }
        </a>

        <b class="arrow"></b>
        @if (childNodes.Any())
        {
            <ul class="submenu">
                @foreach (var childItem in childNodes)
                {
                    @RenderMenuItem(childItem, list)
                }
            </ul>
        }
    </li>
            if (Request.Url.LocalPath.Equals(href, StringComparison.InvariantCultureIgnoreCase))
            {
                <script>
                    $('#@(item.FatherID)').addClass('open active').parents('li').addClass('open active')
                </script>
            }
}
<div id="sidebar" class="sidebar responsive sidebar-fixed">
    <div class="sidebar-shortcuts" id="sidebar-shortcuts">
        <div class="sidebar-shortcuts-large" id="sidebar-shortcuts-large">
            <button class="btn btn-success">
                <i class="ace-icon fa fa-signal"></i>
            </button>
            <button class="btn btn-info">
                <i class="ace-icon fa fa-pencil"></i>
            </button>
            <button class="btn btn-warning">
                <i class="ace-icon fa fa-users"></i>
            </button>
            <button class="btn btn-danger">
                <i class="ace-icon fa fa-cogs"></i>
            </button>
        </div>
    </div>

    @{
        List<CategoryMapping> list = WorkContext.MyDescriperes;
        if (list != null)
        {
            var nodes = list.Where(o => String.IsNullOrEmpty(o.FatherResource)).Where(o => o.IsMenu).OrderBy(o => o.Sort).ThenBy(o => o.Name).ToList();

            <ul class="nav nav-list">
                @if (nodes != null)
                {
                    foreach (var item in nodes)
                    {
                        @RenderMenuItem(item, list)
                    }
                }
            </ul>
            string controller = Request.RequestContext.RouteData.Values["controller"].ToString();
            string action = Request.RequestContext.RouteData.Values["action"].ToString();
            //当前
            var current = list.FirstOrDefault(o => o.Action == action && o.Controller == controller);
            if (current != null && !current.IsMenu)
            {
                <script>
                 $('#@(current.FatherID)').addClass('active').parents('li').addClass('open active')
                </script>
            }
        }
    }
    <div class="sidebar-toggle sidebar-collapse" id="sidebar-collapse">
        <i class="ace-icon fa fa-angle-double-left" data-icon1="ace-icon fa fa-angle-double-left" data-icon2="ace-icon fa fa-angle-double-right"></i>
    </div>
</div>

